/**
 * 
 *    NFC 模块 碰一碰测试
 * 2021.09.03 连接nfc，从设备，测试i2c是否连通 
 * 
 */ 
#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"

#include "iot_errno.h" //==IOT_SUCCESS =0 

#include "hi_io.h"
#include "hi_i2c.h"
#include "nfc_bingo.h"
#include "iot_gpio.h"


static void NFCTask(void *arg)
{
    (void) arg;
    uint8_t data;
    IoTGpioInit(NFC_SDA_IO13);
    IoTGpioInit(NFC_SCL_IO14);

    IoTGpioInit(9);
    IoTGpioSetDir(9,IOT_GPIO_DIR_OUT);         //==载板led初始化

    IoTGpioSetOutputVal(9,0);// 只要一直初始化不成功，则灯不闪
    NFC_Init();
    
    while(1) //连接成功 led 一直闪烁
    { 
        
        IoTGpioSetOutputVal(9,0); 
        usleep(30000);  
        IoTGpioSetOutputVal(9,1); 
        usleep(30000); 
        ReadData(NFC_FIFO_ACCESS, data);
        printf("FIFO Data: %d \n",data);


    }
}




static void NFCDemo(void)
{
    osThreadAttr_t attr;

    attr.name = "NFCTask";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 4096;
    attr.priority = osPriorityNormal;

    if (osThreadNew(NFCTask, NULL, &attr) == NULL) {
        printf("[NFCDemo] Falied to create NFCTask!\n");
    }
}
SYS_RUN(NFCDemo);
